<!DOCTYPE html>
<html xmlns="http://www.thymeleaf.org">
<head>
<meta charset="UTF-8">
<base th:href="@{/}" />
<title>Insert title here</title>
<script src="js/jquery-3.4.1.min.js"></script>
<script src="js/bootstrap.min.js"></script>
<link rel="stylesheet" href="css/bootstrap.min.css" />
<link rel="stylesheet" href="css/Managerstyle.css" />
</head>
<style>
	span{
		font-size: 17px;
	}
</style>
<body>
<div class="contain">
<a href="mc/getAllStructure">返回</a>
	<h3>安排课程</h3>
	<span>请确认信息：</span>
	<br>
	<br>
	<span>开课计划号：</span><span id="cpid" th:text="${coursePlan.cpid}"></span>
	<br>
	<span>学院：</span><span th:text="${coursePlan.lessionPlan.major.acadamy.acdmname}"></span>
	<br>
	<span>专业：</span><span th:text="|${coursePlan.lessionPlan.major.term.tyear}${coursePlan.lessionPlan.major.mjname}|"></span>
	<br>
	<span>授课班级：</span><span th:text="${coursePlan.batch.bname}"></span>
	<br>
	<span>授课教师：</span><span th:text="|${coursePlan.teacher.tname} 教职工号：${coursePlan.teacher.tid}|"></span>
	<br>
	<span>课程名称：</span><span th:text="${coursePlan.lessionPlan.course.cname}"></span>
	<br>
	<span>所需教室类型：</span><span th:text="${classrmtype}=='1'?'普通教室':'多媒体教室'" th:value="${classrmtype}"></span>
	<input type="hidden" id="classrmtype" th:value="${classrmtype}">
	<h4>课程安排</h4>
	<table class="table table-hover">
		<tr>
			<td>周次</td>
			<td>星期</td>
			<td>节次</td>
			<td>教室</td>
			<td>操作</td>
			
		</tr>
		<tr th:each="str:${strlist}" th:id="|tr${str.strid}|">
			<td th:text="|第${str.cycle}周|"></td>
			<td th:text="|星期${str.sweek}|"></td>
			<td th:text="|第${str.strtime}节|"></td>
			<td th:text="|${str.classroom.building.buildname}${str.classroom.clrnum}|"></td>
			<td>
				<a th:href="|javascript:deleteStructure(${str.strid});|">删除</a>
			</td>
		</tr>
	</table>
	
	<div class="text-center">
			<nav>
				<ul class="pagination">
					<li><a th:href="@{/mc/toAddStructure/(pageNo=1,cpid=${cpid},bid=${bid})}">首页</a></li>
					<li><a th:href="@{/mc/toAddStructure/(pageNo=${pageInfo.hasPreviousPage}?${pageInfo.prePage}:1,cpid=${cpid},bid=${bid})}">上一页</a></li>
					<li th:each="page:${pageInfo.navigatepageNums}">
						<a th:class="${pageInfo.pageNum}==${page}?'active'"
						   th:href="@{/mc/toAddStructure/(pageNo=${page},cpid=${cpid},bid=${bid})}">[[${page}]]</a>
					</li>
					<li><a th:href="@{/mc/toAddStructure/(pageNo=${pageInfo.hasNextPage}?${pageInfo.nextPage}:${pageInfo.pages},cpid=${cpid},bid=${bid})}">下一页</a></li>
					<li><a th:href="@{/mc/toAddStructure/(pageNo=${pageInfo.pages},cpid=${cpid},bid=${bid})}">尾页</a></li>
				</ul>
			</nav>
		</div>
	
	<div class="query">
		<form id="form">
		<h1>排课</h1>
		<h1 id="msg"></h1>
			<span>选择教室</span>
			<select id="selectBuild" style="width: 150px;">
				<option>请选择教学楼</option>
				<option th:each="building:${buildlist}" th:value="${building.buildingId}" th:text="${building.buildname}"></option>
			</select>
			<select id="selectClassrm" name="classrmid" style="width: 130px;">
				<option>请选择教室</option>
			</select>
			<div class="structure">
				<br>
				<span>选择时间</span>
				<input type="hidden" name="cpid" th:value="${coursePlan.cpid}">
				<div class="checkbox">
					<span>周次</span>
					<br>
				    <label><input type="checkbox" name="cycle" value="1"> 第1周</label>&nbsp&nbsp&nbsp
				    <label><input type="checkbox" name="cycle" value="2"> 第2周</label>&nbsp&nbsp&nbsp
				    <label><input type="checkbox" name="cycle" value="3"> 第3周</label>&nbsp&nbsp&nbsp
				    <label><input type="checkbox" name="cycle" value="4"> 第4周</label>&nbsp&nbsp&nbsp
				    <label><input type="checkbox" name="cycle" value="5"> 第5周</label>&nbsp&nbsp&nbsp
				    <label><input type="checkbox" name="cycle" value="6"> 第6周</label>&nbsp&nbsp&nbsp
				    <label><input type="checkbox" name="cycle" value="7"> 第7周</label>&nbsp&nbsp&nbsp
				    <label><input type="checkbox" name="cycle" value="8"> 第8周</label>&nbsp&nbsp&nbsp
				    <label><input type="checkbox" name="cycle" value="9"> 第9周</label>&nbsp&nbsp&nbsp
				    <br>
				    <label><input type="checkbox" name="cycle" value="10">第10周</label>&nbsp
				    <label><input type="checkbox" name="cycle" value="11">第11周</label>&nbsp
				    <label><input type="checkbox" name="cycle" value="12">第12周</label>&nbsp
				    <label><input type="checkbox" name="cycle" value="13">第13周</label>&nbsp
				    <label><input type="checkbox" name="cycle" value="14">第14周</label>&nbsp
				    <label><input type="checkbox" name="cycle" value="15">第15周</label>&nbsp
				    <label><input type="checkbox" name="cycle" value="16">第16周</label>&nbsp
				    <label><input type="checkbox" name="cycle" value="17">第17周</label>&nbsp
				    <label><input type="checkbox" name="cycle" value="18">第18周</label>&nbsp
				    <br>
					<span>星期</span>
					<br>
					<label><input type="checkbox" name="sweek" value="1">星期一</label>&nbsp
					<label><input type="checkbox" name="sweek" value="2">星期二</label>&nbsp
					<label><input type="checkbox" name="sweek" value="3">星期三</label>&nbsp
					<label><input type="checkbox" name="sweek" value="4">星期四</label>&nbsp
					<label><input type="checkbox" name="sweek" value="5">星期五</label>&nbsp
					<label><input type="checkbox" name="sweek" value="6">星期六</label>&nbsp
					<label><input type="checkbox" name="sweek" value="7">星期日</label>&nbsp
					<br>
					<span>节次</span>
					<br>
					<label><input type="checkbox" name="strtime" value="1">第1节</label>&nbsp&nbsp
					<label><input type="checkbox" name="strtime" value="2">第2节</label>&nbsp&nbsp
					<label><input type="checkbox" name="strtime" value="3">第3节</label>&nbsp&nbsp
					<label><input type="checkbox" name="strtime" value="4">第4节</label>&nbsp&nbsp
					<label><input type="checkbox" name="strtime" value="5">第5节</label>&nbsp&nbsp
					<label><input type="checkbox" name="strtime" value="6">第6节</label>&nbsp&nbsp
					<label><input type="checkbox" name="strtime" value="7">第7节</label>&nbsp&nbsp
					<label><input type="checkbox" name="strtime" value="8">第8节</label>&nbsp&nbsp
					<label><input type="checkbox" name="strtime" value="9">第9节</label>&nbsp&nbsp
					<label><input type="checkbox" name="strtime" value="10">第10节</label>&nbsp&nbsp
				</div>
			</div>
			<input type="button" id="addStr" class="btn btn-primary" value="添 加" >
			<br>
			<br>
			<br>
			<br>
		</form>
	</div>
</div>
	<script>
		function deleteStructure(id) {
			$.ajax({
	            url: 'mc/deleteStructure',
	            type: 'POST',
	            data: {strid:id}, 
	            success: function() {
	            	$("#tr" + id).remove(); 
	            },
	            error: function (req, status, error) {
	                alert("Ajax请求失败，错误：" + error);
	            }
	        });
	    };
		$(document).ready(function(){
			$("#selectBuild").change(function(){
				var str2 = "<option>请选择</option>" ; 
				$.ajax({
					url: "mc/getClassrmByBuildid",
					type: "GET",
					data: {buildingId: $("#selectBuild").val(),classrmtype: $("#classrmtype").val()},
					success: function(data){
						var str1 = "";
						$("#selectClassrm").empty();
						$("#selectClassrm").append(str2);
						$.each(data,function(index,value){
							str1 = "<option value='" + value.classrmid +"'>" + value.clrnum + "</option>";
							$("#selectClassrm").append(str1);
						});					
					},
					error: function(req,status,error){
						$("#selectClassrm").empty();
						$("#selectClassrm").append(str2);
					}
				});
				
			});
			$("#addStr").click(function(){
				$.ajax({
					url: "mc/addStructure",
					type: "GET",
					data: $("#form").serialize(),
					success: function(data){
						$("#msg").html(data);
					},
					error: function(req,status,error){
						alert("请填写完整信息！");
					}
				});
			});
			
		});
	
	</script>
</body>
</html>